import java.util.Stack;

public class Solution1003 {
    public boolean isValid(String s) {
        Stack<Character> stack=new Stack<>();
        for (char c : s.toCharArray()) {
            stack.push(c);
            while (stack.size()>=3){
                if (stack.peek()!='c'){
                    break;
                }
                stack.pop();
                if (stack.peek()!='b'){
                    stack.push('c');
                    break;
                }
                stack.pop();
                if (stack.peek()!='a'){
                    stack.push('b');
                    stack.push('c');
                }
                stack.pop();
            }
        }
        return stack.isEmpty();
    }

    public static void main(String[] args) {
        System.out.println(new Solution1003().isValid("abcabcababcc"));
    }
}
